import 'package:sil_utils_package/log/SilEntityLog.dart';
/**
 * 设备信息（自己数据库存储的数据）
 */

class DeviceEntity {
  String? id;
  String? psName;
  String? userId;
  String? snNumber;
  String? surplusPower;
  String? realPower;
  String? isPayPower;
  String? powerSet;
  String? usePowerSet;
  String? powerPrice;
  String? moneyType;
  String? moneyUnit;
  String? createMode;
  String? createTime;
  String? isValid;
  String? datasPn;
  String? datasAs;
  String? devcode;
  String? devaddr;
  String? thirdPsId;
  String? powerState;
  String? modelSelection;
  String? equipmentSelection;
  String? isEdit;
  String? timeZoneStr;
  String? stationType;
  DeviceEntity({
    this.id,
    this.psName,
    this.userId,
    this.snNumber,
    this.surplusPower,
    this.realPower,
    this.isPayPower,
    this.powerSet,
    this.usePowerSet,
    this.powerPrice,
    this.moneyType,
    this.moneyUnit,
    this.createMode,
    this.createTime,
    this.isValid,
    this.datasPn,
    this.datasAs,
    this.devcode,
    this.devaddr,
    this.thirdPsId,
    this.powerState,
    this.modelSelection,
    this.equipmentSelection,
    this.isEdit,
    this.timeZoneStr,
    this.stationType,
  });
  DeviceEntity.fromJson(Map<String, dynamic> json) {
    id = SilEntityLog.handleString(json, 'id');
    psName = SilEntityLog.handleString(json, 'psName');
    userId = SilEntityLog.handleString(json, 'userId');
    snNumber = SilEntityLog.handleString(json, 'snNumber');
    surplusPower = SilEntityLog.handleString(json, 'surplusPower');
    realPower = SilEntityLog.handleString(json, 'realPower');
    isPayPower = SilEntityLog.handleString(json, 'isPayPower');
    powerSet = SilEntityLog.handleString(json, 'powerSet');
    usePowerSet = SilEntityLog.handleString(json, 'usePowerSet');
    powerPrice = SilEntityLog.handleString(json, 'powerPrice');
    moneyType = SilEntityLog.handleString(json, 'moneyType');
    moneyUnit = SilEntityLog.handleString(json, 'moneyUnit');
    createMode = SilEntityLog.handleString(json, 'createMode');
    createTime = SilEntityLog.handleString(json, 'createTime');
    isValid = SilEntityLog.handleString(json, 'isValid');
    datasPn = SilEntityLog.handleString(json, 'datasPn');
    datasAs = SilEntityLog.handleString(json, 'datasAs');
    devcode = SilEntityLog.handleString(json, 'devcode');
    devaddr = SilEntityLog.handleString(json, 'devaddr');
    thirdPsId = SilEntityLog.handleString(json, 'thirdPsId');
    powerState = SilEntityLog.handleString(json, 'powerState');
    modelSelection = SilEntityLog.handleString(json, 'modelSelection');
    equipmentSelection = SilEntityLog.handleString(json, 'equipmentSelection');
    isEdit = SilEntityLog.handleString(json, 'isEdit');
    timeZoneStr = SilEntityLog.handleString(json, 'timeZoneStr');
    stationType = SilEntityLog.handleString(json, 'stationType');
  }
  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['psName'] = this.psName;
    data['userId'] = this.userId;
    data['snNumber'] = this.snNumber;
    data['surplusPower'] = this.surplusPower;
    data['realPower'] = this.realPower;
    data['isPayPower'] = this.isPayPower;
    data['powerSet'] = this.powerSet;
    data['usePowerSet'] = this.usePowerSet;
    data['powerPrice'] = this.powerPrice;
    data['moneyType'] = this.moneyType;
    data['moneyUnit'] = this.moneyUnit;
    data['createMode'] = this.createMode;
    data['createTime'] = this.createTime;
    data['isValid'] = this.isValid;
    data['datasPn'] = this.datasPn;
    data['datasAs'] = this.datasAs;
    data['devcode'] = this.devcode;
    data['devaddr'] = this.devaddr;
    data['thirdPsId'] = this.thirdPsId;
    data['powerState'] = this.powerState;
    data['modelSelection'] = this.modelSelection;
    data['equipmentSelection'] = this.equipmentSelection;
    data['isEdit'] = this.isEdit;
    data['timeZoneStr'] = this.timeZoneStr;
    data['stationType'] = this.stationType;
    return data;
  }

  /// 剩余电量百分比
  double get surplusPowerPer {
    double surplusPower = double.parse(this.surplusPower ?? '0');

    return surplusPower;

    // String realPowerStr = (this.realPower == '') ? '0' : '${this.realPower}';
    // int realPower = double.parse(realPowerStr).toInt();

    // if (realPower == 0) return 0;
    // return surplusPower / realPower;
  }
}
